package com.guohui.boot1.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.guohui.boot1.client.Feign1FeignClient;

@AutoConfigureAfter(Feign1FeignClient.class)
@RestController
public class HelloBootController {
  
  private Logger logger = LoggerFactory.getLogger(getClass());
  
  @Autowired
  Feign1FeignClient feign1FeignClient;
  
  @Value("${spring.application.name}")
  private String serviceName;
  
  @RequestMapping(value="/inControl",method=RequestMethod.GET)
  public String inControl() throws Exception {
    throw new Exception("inControl 接口异常测试");
  }
  
  @RequestMapping(value="/hello",method=RequestMethod.GET)
  public String hello( String client) throws Exception {
    logger.debug(client+" say hello to "+serviceName);
    return "success";
  }
  
  @RequestMapping(value="/helloFeign1",method=RequestMethod.GET)
  public String helloFeign1() throws Exception {
    logger.debug("start to connect feign1");
    String success = feign1FeignClient.hello(serviceName);
    if("success".equals(success)) {
      logger.debug("Connection successful");
    }
    return "success";
  }
}
